package org.wms.minbearwcs.utils;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.wms.minbearwcs.dao.config.inf.HttpConfigDao;
import org.wms.minbearwcs.entity.DTO.agv.TUSK.TUSKMission;
import org.wms.minbearwcs.entity.DTO.agv.TUSK.TUSKResponse;

@Slf4j
@Component
@RequiredArgsConstructor
public class TUSKHpptUtil {

    private final RestTemplate restTemplate;

    private final HttpConfigDao httpConfigDao;


    public TUSKResponse dispatchTUSKMission(TUSKMission mission) {
        String tuskIp = httpConfigDao.selectByHttpName(HttpConfigContentPool.TUSK_IP_PORT);
        String url = tuskIp +  "/rpc/createTask";
        return restTemplate
                .exchange(url,
                        HttpMethod.POST,
                        new HttpEntity<>(mission),
                        new ParameterizedTypeReference<TUSKResponse>() {
                        })
                .getBody();

    }
}
